﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using common4gp;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace UnitTest
{
    [TestClass]
    public class TestExtensions
    {
        [TestMethod]
        public void TestIsNull()
        {
            object obj = null;
            Assert.IsTrue(obj.IsNull());
            obj = new object();
            Assert.IsFalse(obj.IsNull());
        }

        [TestMethod]
        public void TestIsNotNull()
        {
            object obj = null;
            Assert.IsFalse(obj.IsNotNull());
            obj = new object();
            Assert.IsTrue(obj.IsNotNull());
        }


        [TestMethod]
        public void TestIsNullOrEmptyCollection()
        {
            List<object> list = null;
            Assert.IsTrue(list.IsNullOrEmpty(), "Null collection error");
            list = new List<object>();
            Assert.IsTrue(list.IsNullOrEmpty(), "Empty collection error");
            list.Add(new object());
            Assert.IsFalse(list.IsNullOrEmpty(), "Not empty collection error");
        }

        [TestMethod]
        public void TestExceptionDetailedMessage()
        {
            Exception child11 = new ArgumentNullException("child1-1");
            Exception child1 = new ArgumentException("child1", child11);
            Exception root = new IndexOutOfRangeException("root", child1);
            Console.WriteLine(root.DetailedMessage());
        }


        [TestMethod]
        public void TestTruncate()
        {
            Assert.AreEqual("12", "123456".Truncate(2));
            Assert.AreEqual("123...", "123456789".Truncate(6));
            Assert.AreEqual("123", "123".Truncate(3));
        }
    }
}
